package com.smart.controller;

import com.smart.common.PageInfo;
import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.model.request.ProjectReportDetailRequest;
import com.smart.model.request.ProjectReportStatisticsRequest;
import com.smart.model.request.ProjectTempTaskAddRequest;
import com.smart.model.request.ProjectTempTaskRequest;
import com.smart.model.request.ProjectTempTaskUpdateRequest;
import com.smart.model.vo.ProjectReportDetailVO;
import com.smart.model.vo.ProjectTempTaskVO;
import com.smart.model.vo.ProjectVO;
import com.smart.service.ProjectTempTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/task")
@Api(tags = {"临时提报任务模块"})
public class ProjectTempTaskController {

    @Autowired
    private ProjectTempTaskService projectTempTaskService;

    @WebAccess(login = true)
    @ApiOperation(value = "【共用】查看", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<ProjectTempTaskVO> getByKey(@PathVariable("id") long id) {
        return WebResponse.build(projectTempTaskService.getByKey(id));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "【云监管】撤销", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/revoke/{id}")
    public WebResponse<Boolean> revokeByKey(@PathVariable("id") long id) {
        return WebResponse.build(projectTempTaskService.revokeByKey(id));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "【云监管】作废", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/cancel/{id}")
    public WebResponse<Boolean> cancelByKey(@PathVariable("id") long id) {
        return WebResponse.build(projectTempTaskService.cancelByKey(id));
    }

    @WebAccess(login = true)
    @ApiOperation("【云监管】分页查询")
    @PostMapping("/supervise/pageQuery")
    public WebResponse<PageInfo<ProjectTempTaskVO>> supervisePageQuery(@RequestBody ProjectTempTaskRequest request) {
        return WebResponse.build(projectTempTaskService.supervisePageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【云监管】新增")
    @PostMapping("/add")
    public WebResponse<Boolean> add(@Valid @RequestBody ProjectTempTaskAddRequest request) {
        return WebResponse.build(projectTempTaskService.add(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【云监管】修改")
    @PostMapping("/update")
    public WebResponse<Boolean> updateByKey(@Valid @RequestBody ProjectTempTaskUpdateRequest request) {
        return WebResponse.build(projectTempTaskService.updateByKey(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【云监管|云管理】任务提交项目名单")
    @PostMapping("/statistic")
    public WebResponse<PageInfo<ProjectVO>> statisticProjectReport(@Valid @RequestBody ProjectReportStatisticsRequest request) {
        return WebResponse.build(projectTempTaskService.statisticProjectReport(request));
    }

    @WebAccess(login = true)
    @ApiOperation("【云监管】任务提交项目名单>临时提报详情")
    @PostMapping("/reportDetail")
    public WebResponse<ProjectReportDetailVO> projectReportDetail(@Valid @RequestBody ProjectReportDetailRequest request) {
        return WebResponse.build(projectTempTaskService.projectReportDetail(request));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "【云监管】获取临时提报编号", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/getTempTaskCode")
    public WebResponse<String> getFileCode() {
        return WebResponse.build(projectTempTaskService.getTempTaskCode());
    }

    @WebAccess(login = true)
    @ApiOperation("【云管理】分页查询")
    @PostMapping("/manage/pageQuery")
    public WebResponse<PageInfo<ProjectTempTaskVO>> managePageQuery(@RequestBody ProjectTempTaskRequest request) {
        return WebResponse.build(projectTempTaskService.managePageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "临时周报任务下载文件类型", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/fileType/{id}")
    public WebResponse<String> fileType(@PathVariable("id") long id) {
        return WebResponse.build(projectTempTaskService.fileType(id));
    }
}
